#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "school.h"
#include "student.h"

#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //使用ui对象找到单选按钮的对象，调用对应的函数，这是单选按钮的选中状态(true:选中，false:未选中)
    ui->radioButton->setChecked(true);
    //设置单选按钮的可选中状态
    ui->radioButton->setCheckable(true);

    //使用代码关联信号和槽
    //当点击按钮时，触发点击事件，系统会调用clicked发送信号给连接的接受者，接受者的槽函数会被自动调用执行(单选按钮会触发抽屉函数)
    //toggle函数特点是：在两个状态间切换
    QObject::connect(ui->pushButton_4, SIGNAL(clicked()),   ui->radioButton , SLOT(toggle()) );
    //    QObject::connect(ui->pushButton_4, SIGNAL(clicked()),   this , SLOT(close()) );
    QObject::connect(ui->pushButton_4, SIGNAL(clicked()),   ui->pushButton_3 , SLOT(hide()) );
    //一个信号可以对应多个接收者的槽函数（一个信号可以 对应多个槽）


    // ---------------------------------------------------------
    //创建学校对象,并将当前的MainWindow作为它的父对象
    school = new  School();
    student = new Student();

    //连接信号和槽
    connect(school, SIGNAL(sendMessage()), student, SLOT(study()));

    //触发自定义信号---相当于点击按钮的事件
    emit school->sendMessage();

}

MainWindow::~MainWindow()
{
    delete ui;
    delete school;
    delete student;
}


void MainWindow::on_pushButton_clicked()
{
    qDebug() << "aaaaaa" << endl;
}

void MainWindow::on_pushButton_5_clicked()
{
    qDebug() << "bbbbbbbbbb" << endl;
}

int MainWindow::add(int a, int b){
    qDebug() << "a: " << a << "b: " << b << endl;
    return 0;
}
